<?php
//-------------------------------------------------------------------------------------------------------
//    header("Cache-Control: no-cache, must-revalidate");
//    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
    //---------------------------------------------------------------------------------------------------
    require_once('../config.inc.php');

    require_once($config['xajax']['path'] . 'xajax.inc.php');
    require_once($config['app_dir'] . '/classes/rates.server.php');
    require_once($config['app_dir'] . '/classes/perf.server.php');
    require_once($config['app_dir'] . '/classes/currency.server.php');
    require_once($config['app_dir'] . '/classes/forecasts.server.php');
    require_once($config['app_dir'] . '/classes/sparklines.server.php');
    require_once($config['app_dir'] . '/classes/RemindPassword.server.php');
    require_once($config['app_dir'] . '/classes/class.calc2.php');
    require_once($config['app_dir'] . '/classes/tracks.class.php');
    require_once($config['app_dir'] . '/classes/class.timezone.php');
    require_once($config['app_dir'] . '/classes/class.payment.php');
    require_once($config['app_dir'] . '/classes/translation.class.php');
    require_once($config['app_dir'] . '/classes/archive.class.php');
    //---------------------------------------------------------------------------------------------------
    //error_reporting(E_ALL);
    error_reporting(E_ALL & ~E_NOTICE);

    //---------------------------------------------------------------------------------------------------

    require_once($config['app_dir'] . '/classes/staff.class.php');
    require_once($config['app_dir'] . '/includes/template.class.php');

    //---------------------------------------------------------------------------------------------------
    $Staff = new objStaff($config['app_id']);
/*
	echo 'request '; var_dump($_REQUEST);
	echo 'post '; var_dump($_POST);
	echo 'get '; var_dump($_GET);
	echo 'staff '; var_dump($Staff->getSystem());
*/
	//---------------------------------------------------------------------------------------------------
    // SignOut
    //---------------------------------------------------------------------------------------------------
    if ( array_key_exists('logoff', $_GET) && '1' == $_GET['logoff'] ) {
        $Staff->Logout();
        header('Location:'.$_SERVER["PHP_SELF"]);
    }
	//---------------------------------------------------------------------------------------------------
    $menu = false;
    $main_menu = false;
    $sub_menu = false;

    if( array_key_exists('m', $_REQUEST) && !empty($_REQUEST['m']) ) $menu = $_REQUEST['m'];
    if( array_key_exists('p', $_REQUEST) && !empty($_REQUEST['p']) ) $main_menu = $_REQUEST['p'];
    if( array_key_exists('s', $_REQUEST) && !empty($_REQUEST['s']) ) $sub_menu = $_REQUEST['s'];
    if( array_key_exists('gad', $_REQUEST) && !empty($_REQUEST['gad']) ) $Staff->Session->put('gad', $_REQUEST['gad']);
	//---------------------------------------------------------------------------------------------------
	if( array_key_exists('system', $_GET) &&
	   array_key_exists('selectsystem_system', $_POST) &&
	   $_GET['system'] != $_POST['selectsystem_system'] ) {

		header('Location:' . "/$menu.html");
	}
	//---------------------------------------------------------------------------------------------------
	header('Content-Type: text/html; charset=utf-8');
	//---------------------------------------------------------------------------------------------------
    require_once($config['app_dir'] . '/classes/menu.class.php');

    //---------------------------------------------------------------------------------------------------

    $TranslationConf = objTranslationConf::GetInstance();

    $TranslationConf->RenderFile('_form_auth');
    $TranslationConf->RenderFile('_order_status');
    $TranslationConf->RenderFile('breadcrumb');
    $TranslationConf->RenderFile('_forecasts');
    $TranslationConf->RenderFile('_live_assistance');
    $TranslationConf->RenderFile('_sparklines');
    $TranslationConf->RenderFile('_rates');
    $TranslationConf->RenderFile('_guarantee');
    $TranslationConf->RenderFile('_trial');
    $TranslationConf->RenderFile('_subscribe');
    $TranslationConf->RenderFile('_EmailUnsubscribe');
    $TranslationConf->RenderFile('EmailSignature');
    $TranslationConf->RenderFile('EmailSubscrDays');
    $TranslationConf->RenderFile('EmailTrial');
    $TranslationConf->RenderFile('_fxbanner');
    $TranslationConf->RenderFile('menu_langselector');
    $TranslationConf->RenderFile('_about_partners');
    $TranslationConf->RenderFile('_form_calc_result');
    $TranslationConf->RenderFile('news');
    $TranslationConf->RenderFile('_info_forecasts');
    $TranslationConf->RenderFile('_ForecastItem');
    $TranslationConf->RenderFile('_TrackForecasts');
	$TranslationConf->RenderFile('_PerformanceBlock');
	$TranslationConf->RenderFile('_service_map_performance');


    //$TranslationConf->RenderAllFiles();
    $TranslationLangSelector = new objTranslationLangSelector('en');
    //$SystemSelector = new objSystemSelector();

    $TranslationMessage = objTranslationMessage::GetInstance();
    $TranslationMessage->SetLang($TranslationLangSelector->getLang());
//    var_dump($TranslationMessage->getData());
	$Staff->getSystem();

    //---------------------------------------------------------------------------------------------------

    $URLTranslator = new objURLTranslator($menu);
    if( !$URLTranslator->isEmpty() ){
        $main_menu = $URLTranslator->getMainMenu();
        $sub_menu = $URLTranslator->getSubMenu();
    }//urltranslator
    //echo "1";var_dump($main_menu);
    //echo "2";var_dump($sub_menu);

    //$Menu = new objMenu($main_menu, $sub_menu);
    $Menu = new objMenu($menu, $main_menu, $sub_menu);
    //$Menu = new objMenu('rd', false);
    $Menu->TranslationMessage= $TranslationMessage;
	
	 //---------------------------------------------------------------------------------------------------

    $xajax = new xajax();
    $xajax->debugOff();
    //$xajax->statusMessagesOn();
    //$xajax->errorHandlerOff();
		
    $xajax->setLogFile($config['log']['path'].'xajax.log');

    $xajax->registerFunction("showLastForecasts");
    $xajax->registerFunction("showSparkLinesOut");
    $xajax->registerFunction("showSparkLinesIn");
    $xajax->registerFunction("showLastRates");
    $xajax->registerFunction("showPerfSignals");
    $xajax->registerFunction("showPerfMaps");
    $xajax->registerFunction("showCurrency");
    $xajax->registerFunction("getCalcResult");
    $xajax->registerFunction("getCalcResultPair");
    $xajax->registerFunction("showTimeZones");
    $xajax->registerFunction("processRemindPasswordForm");
    $xajax->registerFunction("reloadTrackRecord");
    $xajax->registerFunction("showTrackRecordForecasts");
    $xajax->registerFunction("showTrackRecord");
    $xajax->registerFunction("showTracksPairLite");
    $xajax->registerFunction("getDiscount");
    $xajax->registerFunction("flashReloadHandler");
    $xajax->registerFunction("ArchiveChangeSystem");
    $xajax->registerFunction("ArchiveChangePair");
    $xajax->registerFunction("ArchiveChangeYear");
    $xajax->registerFunction("ArchiveChangeMonth");
    $xajax->registerFunction("ArchiveChangePart");
    $xajax->registerFunction("ShowDashboardForecast");
    $xajax->registerFunction("ShowDashboard");

	$xajax->processRequests();
	
	ob_start();
	$xajax->printJavascript(addslashes($config['xajax']['js']));
	$xajaxJS = ob_get_contents();	
	ob_end_clean(); 
    //---------------------------------------------------------------------------------------------------
    $Template = new objTemplate();
    $Template->Assign('xajaxjavascript', $xajaxJS);

    $Template->Assign_by_ref('Staff', $Staff);

    $Template->Assign('menu_main', $Menu->getMainMenu());
    $Template->Assign('menu_sub', $Menu->getSubMenu());
    $Template->Assign('menu_page', $Menu->getPageMenu());

    $Template->Assign('content', $Menu->getContent());

    $Template->Assign('language_selector', $TranslationLangSelector->Render());
//    $Template->Assign('system_selector', $SystemSelector->Render());

    $Template->Assign('title', $Menu->getTitle());
    $Template->Assign('keywords', $Menu->getKeywords());
    $Template->Assign('description', $Menu->getDescription());

    $Template->Assign('menu_top', $Menu->getMenuTop());
    $Template->Assign('header', $Menu->getHeader());

    $Template->Assign('is_left', $Menu->getIsLeft());
    $Template->Assign('menu_header', $Menu->getMenuLeftHeader());
    $Template->Assign('content_left', $Menu->getContentLeft());

    $Template->Assign('is_right',  $Menu->getIsRight());
    $Template->Assign('content_right', $Menu->getContentRight());
    $Template->Assign('rand_num', $Menu->getRand());

    //---------------------------------------------------------------------------------------------------
    $Template->Display('page.tpl');
//-------------------------------------------------------------------------------------------------------
?>
